<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>55社区</title>
    <meta name="description" content="">
    <meta name="keywords" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <link rel="icon" type="image/png" href="/theme/default/images/favicon.png">
    <link href="${ctx}/static/css/amazeui.min.css" rel="stylesheet" type="text/css" />
    <link href="${ctx}/static/css/style.css" rel="stylesheet" type="text/css" />
    <script src="${ctx}/static/js/jquery-1.10.2.min.js"></script>
    <script src="${ctx}/static/js/time.js"></script>
</head>
<body>
<header data-am-widget="header" class="am-header am-header-default sq-head ">
    <div class="am-header-left am-header-nav">
        <a href="javascript:history.back()" class="">
            <i class="am-icon-chevron-left"></i>
        </a>
    </div>
    <h1 class="am-header-title">
        <a href="" class="">注册</a>
    </h1>
</header>
<div style="height: 49px;"></div>
<form action="#" onsubmit="return false" class="register">
    <input type="text" name="mobile" id="phone" placeholder="请输入手机号" column="user_phone" checkMsg="手机号已被注册" checkMsg1="手机号不能为空" class="login-password checkInfo">
    <input type="text" name="username" placeholder="请输入用户名" column="user_name" checkMsg="用户名已被注册" checkMsg1="用户名不能为空" class="login-password checkInfo">
    <div class="yzm">
        <input type="text" class="reg-yzm" placeholder="输入验证码" name="code" style="width: 65%"/>
        <img src="${ctx}/code.do" alt="" width="100" height="32" class=""
             style="height:38px;cursor:pointer;margin-left: 10px;border-radius: 2px" onclick="this.src=this.src+'?'">
    </div>
    <input type="password" id="password" name="password" placeholder="请输入密码" class="login-password checkInfo">
    <input type="password" id="repassword" name="repassword" placeholder="确认密码" class="login-name checkInfo">
    <span class="message" style="color: red;margin-left: 50px;"></span>
    <%--<button type="button" class="login-btn" id="register-btn>立即注册</button>--%>
    <input type="button" class="login-btn" id="register-btn" value="立即注册">
</form>


<script>

    var is = 1;

    $(".checkInfo").blur(function () {
        var msg = $(this).attr("checkMsg"); //提示信息
        var msg1 = $(this).attr("checkMsg1"); //提示信息
        console.info(msg1);
        //console.info(msg);
        var key = $(this).attr("column");
        var val = $(this).val().trim();// 获取输入框的值
        $(".message").html("");
        if(""==val){
            $(".message").html(msg1);
            is = 0;
            return;
        }
        $.post("${ctx}/user/check.do", {"key": key, "val": val}, function (data) {
            if (data.state == 0) {
                //console.info("sds");
                //$("#showMsg").slideUp();
            } else {
                $(".message").html(msg);
                console.info(msg);
                is = 0;
                $(this).focus();
            }
        }, 'json');
    });

    $("#register-btn").click(function () {
        if (is == 0) {
            return;
        }
        var phone = $("#phone").val();
        var reg = /^(13[0-9]|14[5|7]|15[0|1|2|3|5|6|7|8|9]|18[0|1|2|3|5|6|7|8|9])\d{8}$/;
        if (reg.test(phone)) {
            console.info("手机号正确");
            //$("#showMsg").slideUp();
        } else {
            $(".message").text("");
            $(".message").text("手机号格式不正确，请输入正确的手机号");
            console.info("手机号错误");
            return;
        }
        var pwd = $("#password").val();
        var repwd = $("#repassword").val();
        console.info(pwd)
        //console.info();
        //console.info(is);
        if (pwd != repwd) {
            $(".message").text("");
            $(".message").text("两次输入的密码不一致，请重新确认");
            return;
        }
        // 给注册按钮绑定事件
        var myData = $(".register").serialize();
        console.info(myData);
        $.post("${ctx}/user/check.do", myData, function (data) {
            if (data.state == 1) {
                $(".message").html("");
                $(".message").html(data.msg);
            } else {
                location.href = "${ctx}/static/login.jsp";
            }
        });
    });
</script>
</body>
</html>


